//
// Created by 32827 on 2023/11/23.
//
#include "yzf_sys_tick.h"
YZF_BOOL yzf_sys_tick_countFlag(){
    return (SysTick->CTRL & (0b1 << SysTick_CTRL_COUNTFLAG_Pos)) == 0 ? YZF_FALSE : YZF_TRUE;
}
YZF_RESULT yzf_sys_tick_source_clk_div_8(){
    SysTick->CTRL &= ~(0b1 << SysTick_CTRL_CLKSOURCE_Pos);
    return YZF_OK;
}
YZF_RESULT yzf_sys_tick_source_clk(){
    SysTick->CTRL |= (0b1 << SysTick_CTRL_CLKSOURCE_Pos);
    return YZF_OK;
}
YZF_RESULT yzf_sys_tick_interrupt_enable(){
    SysTick->CTRL |=(0b1 << SysTick_CTRL_TICKINT_Pos);
    return YZF_OK;
}
YZF_RESULT yzf_sys_tick_interrupt_disable(){
    SysTick->CTRL &= ~(0b1 << SysTick_CTRL_TICKINT_Pos);
    return YZF_OK;
}
YZF_RESULT yzf_sys_tick_enable(){
    SysTick->CTRL |= (0b1 << SysTick_CTRL_ENABLE_Pos);
    return YZF_OK;
}
YZF_RESULT yzf_sys_tick_dispose(){
    SysTick->CTRL &= ~(0b1 << SysTick_CTRL_ENABLE_Pos);
    return YZF_OK;
}
YZF_RESULT yzf_sys_tick_load(uint32_t data){
    SysTick->LOAD = data & 0xFFFFFF;
    return YZF_OK;
}
uint32_t yzf_sys_tick_var(){
    return SysTick->VAL & 0x00FFFFFF;
}
YZF_RESULT yzf_sys_tick_set_var(uint32_t data){
    SysTick->VAL = data & 0xFFFFFF;
    return YZF_OK;
}
uint32_t yzf_sys_tick_get_10ms_ref(){
    return SysTick->CALIB & 0x00FFFFFF;
}
YZF_BOOL yzf_sys_tick_no_ref(){
    return (SysTick->CALIB & (0b1 << SysTick_CALIB_NOREF_Pos)) == 0 ? YZF_FALSE : YZF_TRUE;
}
YZF_BOOL yzf_sys_tick_is_exact_ref(){
    return  (SysTick->CALIB & (0b1 << SysTick_CALIB_SKEW_Pos)) == 0 ? YZF_TRUE : YZF_FALSE;
}